package com.example.seataxa.account.service.impl;

import com.example.seataxa.account.service.AccountService;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

import static com.alibaba.nacos.client.utils.EnvUtil.LOGGER;

/**
 * @author 季舟
 * @Date 2024-09-14 14:44
 */
@Service
public class AccountServiceImpl implements AccountService {
    @Resource
    private JdbcTemplate jdbcTemplate;

    @Override
    @Transactional
    public void debit(String userId, int money) {
        LOGGER.info("Deducting balance SQL: update account_tbl set money = money - {} where user_id = {}", money, userId);

        jdbcTemplate.update("update account_tbl set money = money - ? where user_id = ?", money, userId);
        LOGGER.info("Account Service End ... ");
    }
}
